﻿using EYangFramework.Business.SystemManager.Interfaces;
using EYangFramework.Domain.Entitys.Entrys;
using EYangFramework.Domain.Repositorys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EYangFramework.Business.SystemManager.Implementation
{
    public class BLLRole : IBLLRole
    {
        private IRepository<Role> RepositoryRole;
        public BLLRole(IRepository<Role> repositoryRole)
        {
            this.RepositoryRole = repositoryRole;
        }

        public bool DeleteRole(Guid id)
        {
            RepositoryRole.Delete(t => t.ID == id || (t.PARENT != null && t.PARENT.ID == id));
            return true;
        }

        public void Dispose()
        {
            (RepositoryRole as Repository<Role>).DbContext.Dispose();
        }

        public List<Role> GetAllList()
        {
            return RepositoryRole.GetAllList();
        }

        public Role GetBusinessByID(Guid id)
        {
            return RepositoryRole.Get(id);
        }

        public bool InsertRole(Role role)
        {
            RepositoryRole.Insert(role);
            return true;
        }

        public bool UpdateRole(Role role)
        {
            RepositoryRole.Update(role);
            return true;
        }
    }
}
